package com.dms.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class FileUtils {
    public static  final String UPLOAD_PATH="E:\\image\\uploads\\";
    public static String upload(MultipartFile file) throws IOException {
        //文件后缀
        final  String fileSuffix= file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')+1);
        //文件名
        String fileName= UUID.randomUUID().toString().replace("-","")+"."+fileSuffix;


        //文件写入
        File descFile = new File(UPLOAD_PATH,fileName);
        file.transferTo(descFile);

        //文件url
        String URL="/uploads/"+fileName;
        return URL;




    }
}
